--[[
-- @Author:      feilong
-- @DateTime:    2020-11-13 23:05:48
-- @Description: rabbitmq消息的处理
-- @Example:
            local msg = {key = "value1", key2 = "value2"}
            local headers = {}
            headers["destination"] = "/exchange/test" --交换机名字
            headers["receipt"] = "msg#1"
            headers["app-id"] = "skynet_rabbitmq"
            headers["persistent"] = "true"
            headers["content-type"] = "application/json"
            headers["routing-key"] = "test" --交换机类型要使用headers, 还要绑定队列
            g.sendRabbit(msg, headers)




        --监听要用一个服务来写
        local rabbitmq = require "snex.rabbitmqstomp"
        local server_config = g.getServerConf()
        local conf = server_config.rabbit
        local host = conf[1]
        local account = conf[2]
        local mq =  rabbitmq.connect(host, account)
        local headers = {}
        headers["destination"] = "/queue/test"
        headers["persistent"] = "true"
        headers["app-id"] = "skynet_rabbitmq"
        headers["id"] = "skynet_rabbitmq_subcription"

        mq:subscribe(
                headers,
                function(data)
                    g.log.debug("consumed:", data)
                    mq:unsubscribe(headers)
                end
        )
        g.fork(function()
            g.sleep(50)
            mq:receive()
        end)
--]]


---------------------------------------------------------
-- class
---------------------------------------------------------
local Service = class("Rabbit")

function Service:ctor(name)
    self.manager = new("rabbitpub.manager")
    self:register()
end

function Service:register()
    g.register('start', handler(self, self.onStart))
    g.register('close', handler(self, self.onClose))

end

function Service:onStart()

    return true
end
function Service:onClose()
    return true
end

return Service